package com.situ.student.common;

import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@WebListener
public class MyServletContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("contextInitialized");

        InputStream is = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("jdbc.properties");
        Properties prop = new Properties();
        try {
            prop.load(is);

            String driver = prop.getProperty("jdbc.driver");
            String url = prop.getProperty("jdbc.url");
            String username = prop.getProperty("jdbc.user");
            String password = prop.getProperty("jdbc.password");

            Global.driver = driver;
            Global.jdbcUrl = url;
            Global.username = username;
            Global.password = password;

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
